/**
 * COPYRIGHT. Harry Wu 2011. ALL RIGHTS RESERVED.
 * Project: just-core
 * Author: Harry Wu <harrywu304@gmail.com>
 * Created On: Aug 16, 2011 10:13:06 AM
 *
*/ 
package org.justframework.core.router;

import java.util.List;

/**
 * 
 * Master slave router, mainly for database access
 */
public class MasterSlaveRouter<T> implements Router<T> {
	
	private List<T> nodes;
	
	public MasterSlaveRouter(){
	}
	
	public MasterSlaveRouter(List<T> nodes){
		this.nodes = nodes;
	}

	/* (non-Javadoc)
	 * @see org.justframework.core.support.HostRouter#getHosts()
	 */
	public List<T> getNodes() {
		return nodes;
	}

	/* (non-Javadoc)
	 * @see org.justframework.core.support.HostRouter#setHosts(java.util.List)
	 */
	public void setNodes(List<T> nodes) {
		this.nodes = nodes;
	}

	/* (non-Javadoc)
	 * @see org.justframework.core.support.HostRouter#locate(java.lang.String)
	 */
	public T locate(String... keys) {
		if("w".equalsIgnoreCase(keys[0])){
			return nodes.get(0);
		} else if("r".equalsIgnoreCase(keys[0])){
			return nodes.get(1);
		}
		return null;
	}

}
